package Test;

import java.net.InetAddress;

public class Test02 {
    public static void main(String[] args) {
        //通过InetAddress获得远程服务器的所有ip，
        // 通过域名，比如sina.com,用程序获得其服务器的ip（要考虑有多个服务器的情况）
        try {
            InetAddress ipv4 = InetAddress.getLocalHost();
            String nativeip = ipv4.getHostAddress();
            System.out.println("本机名：" + ipv4.getHostName());
            System.out.println("本机IP:" + nativeip);

            String url = "www.taobao.com";
            InetAddress ip = null;
            ip = InetAddress.getByName(url);
            System.out.println("域名" + url + "对应的IP地址是：" + ip.getHostAddress());

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
